/**
 * CharGen.java
 * 
 * @author	Joe Scharnitzke
 * Date: 	May 27, 2011
 * 
 * This class contains a library of functions for character
 * generation in just about any RPG.
 *
 * Change Log:
 * 	06/10/11 10:58 - (v1.0) Release
 * 	May 27, 2011 2:40:40 PM - (v0.1) Initial Implementation
 */

package rng;

import resources.*;

public class CharGen
{
	/**
	 * Generates randomized stats for a character in
	 * much less time than rolling one out would take.
	 * 
	 * @param numStats total number of attributes to roll
	 * @param minMod minimum sum of all stat modifiers
	 * @return an array of stats for character creation
	 */
	
	public int[] statGenMinMod(int numStats, int minMod)
	{
		int totMod = 0, stat = 0;
		int[] stats = new int[numStats + 1];
		
		//loop until we're sure we've initialized everything 
		//AND our total modifier is higher than the min
		for(int i = 0; i < numStats || totMod < minMod; i++)
		{
			int index = i % numStats;
			stat = (int)(Math.random() * 16 + 3);
			
			//remove the modifier from the old stat before it gets replaced
			if(i > numStats)
				totMod -= StatModifiers.dnd35Standard().get(stats[index]);
			
			stats[index] = stat;
			totMod += StatModifiers.dnd35Standard().get(stat);
		}
		
		stats[numStats] = totMod;
		
		return stats;
	}
}
